package com.java.demo.model;

/**
 * 策略模式应用
 *
 * @auther zhangwj
 * @date 2020/8/13 9:47 上午
 */
public class SimUDuck {

    public static void main(String[] args) {
        AbstractDuck duck = new MallardDuck();
        duck.display();
        duck.quack(new Quack());
        duck.swim();
        duck.fly(new CanFly());
    }
}

abstract class AbstractDuck {

    // 叫
    protected void quack(IQuack quack) {
        quack.quack();
    }

    // 游泳
    protected void swim() {
        System.out.println("游泳");
    }

    protected void fly(IFly fly) {
        fly.fly();
    }

    // 外观
    protected abstract void display();
}

// 绿头
class MallardDuck extends AbstractDuck {

    @Override
    protected void display() {
        System.out.println("绿头");
    }
}

// 红头
class RedHeadDuck extends AbstractDuck {

    @Override
    protected void display() {
        System.out.println("红头");
    }
}

interface IFly {

    void fly();
}

class CanFly implements IFly {

    @Override
    public void fly() {
        System.out.println("会飞");
    }
}

class NoFly implements IFly {

    @Override
    public void fly() {
        System.out.println("不会飞");
    }
}

interface IQuack {

    void quack();
}

class Quack implements IQuack {

    @Override
    public void quack() {
        System.out.println("呱呱叫");
    }
}